<template>
  <div id="redactDialog">
    <el-dialog class="box" title="编辑" :visible.sync="redactdialogShow" :before-close="handleClose">
      <div class="wgAddcontent">
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              物联网关编号：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <input disabled style="border: none;background-color: #fff" v-model="webGateRedactForm.asset_no" class="dialogInput"/>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content bg-purple-light" style="text-align: right">
              状态：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple-light">
              <el-select v-model="webGateRedactForm.asset_status" placeholder="请选择">
                <el-option
                  v-for="item in statusoptions"
                  :key="item.id"
                  :label="item.status"
                  :value="item.status">
                </el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              <span style="color: #DE6669;">*</span>
              物联网关名称：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <input v-model="webGateRedactForm.asset_name" class="dialogInput longInput" placeholder="请输入网关名称"/>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              品牌：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <el-select v-model="webGateRedactForm.brand" placeholder="请选择品牌">
                <el-option
                  v-for="item in brandoptions"
                  :key="item.id"
                  :label="item.brand"
                  :value="item.brand">
                </el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content bg-purple-light" style="text-align: right">
              内存：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple-light">
              <el-select v-model="webGateRedactForm.ram" placeholder="请选择内存">
                <el-option
                  v-for="item in ramoptions"
                  :key="item.id"
                  :label="item.ram"
                  :value="item.ram">
                </el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              型号：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <el-select v-model="webGateRedactForm.model" placeholder="请选择">
                <el-option
                  v-for="item in modeloptions"
                  :key="item.id"
                  :label="item.model"
                  :value="item.model">
                </el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content bg-purple-light" style="text-align: right">
              硬盘：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple-light">
              <el-select v-model="webGateRedactForm.rom" placeholder="请选择硬盘">
                <el-option
                  v-for="item in romoptions"
                  :key="item.id"
                  :label="item.rom"
                  :value="item.rom">
                </el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              序列号：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <input v-model="webGateRedactForm.sn" class="dialogInput"/>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content bg-purple-light" style="text-align: right">
              操作系统：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple-light">
              <el-select v-model="webGateRedactForm.asset_os" placeholder="请选择操作系统">
                <el-option
                  v-for="item in osoptions"
                  :key="item.id"
                  :label="item.os"
                  :value="item.os">
                </el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              供应商：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <input v-model="webGateRedactForm.provider" class="dialogInput longInput"/>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              联系人：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <input v-model="webGateRedactForm.contact" class="dialogInput"/>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content bg-purple-light" style="text-align: right">
              联系电话：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple-light">
              <input v-model="webGateRedactForm.contact_number" class="dialogInput"/>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              采购时间：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <el-date-picker
                v-model="webGateRedactForm.purchase_time"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content bg-purple-light" style="text-align: right">
              保修到期时间：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple-light">
              <el-date-picker
                v-model="webGateRedactForm.warranty_period"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" style="text-align: right">
            <div class="grid-content bg-purple">
              备注：
            </div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <textarea class="redactText" v-model="webGateRedactForm.remarks"></textarea>
            </div>
          </el-col>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <span style="float:left; color: #69727E; font-size: 14px;">注：<i style="color: #EC6E70;">*</i> 为必填</span>
        <el-button v-if="this.webGateRedactForm.asset_name !== ''" type="primary" @click="webGateRedact()">保 存</el-button>
        <el-button v-if="this.webGateRedactForm.asset_name === ''" type="primary" disabled>保 存</el-button>
        <el-button type="info" @click="handleClose()">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import axios from 'axios'

  export default {
    props: ['userIndex', 'userRow'],
    data() {
      return {
        dialogFormVisible: false,
        // 新增数据
        webGateRedactForm: [],
        // 下拉框
        statusoptions: [{
          id: 0,
          status: '未使用'
        }, {
          id: 1,
          status: '已使用'
        }, {
          id: 2,
          status: '其他'
        }],
        modeloptions: [],
        brandoptions: [],
        ramoptions: [],
        romoptions: [],
        osoptions: [],
        // 以下为接口
        submitData: {
          access_token: window.localStorage.getItem('access_token'),
          type: 'asset_config_get'
        },
        detaildata: {
          access_token: window.localStorage.getItem('access_token'),
          type: 'asset_get',
          data: {
            condition: {
              asset_no: this.userRow.asset_no
            }
          }
        },
        redactWebGateData: {
          access_token: window.localStorage.getItem('access_token'),
          type: 'asset_mod',
          data: {
            condition: {
              asset_no: '',
              asset_status: 0,
              asset_name: '',
              create_time: '',
              brand: '',
              model: '',
              ram: '',
              rom: '',
              sn: '',
              asset_os: '',
              provider: '',
              contact: '',
              contact_number: '',
              purchase_time: '',
              warranty_period: '',
              remarks: ''
            }
          }
        }
      }
    },
    created() {
      this.redactdialogShow = true
    },
    mounted() {
      this.assetConfigData()
      this.formParent()
      this.webDetail()
    },
    methods: {
      // 确认编辑
      webGateRedact() {
        this.redactWebGateData.data.condition = this.webGateRedactForm
        var statusNum = ''
        if (this.webGateRedactForm.asset_status === '未使用') {
          statusNum = 0
        } else if (this.webGateRedactForm.asset_status === '已使用') {
          statusNum = 1
        } else if (this.webGateRedactForm.asset_status === '其他') {
          statusNum = 2
        }
        this.redactWebGateData.data.condition.asset_status = statusNum
        axios.post('/asset', this.redactWebGateData, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          console.log(res)
          this.handleClose()
        })
          .catch(function(error) {
            console.log(error)
          })
      },
      // 子组件传值
      handleClose() {
        const dialogShow = this.dialogFormVisible // 所需要传的值
        this.$emit('giveFalse', dialogShow) // 传值的参数
      },
      // 接受父组件的值
      formParent() {
        console.log(this.userIndex)
        console.log(this.userRow)
      },
      // 下拉配置
      assetConfigData() {
        axios.post('/asset', this.submitData, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.modeloptions = res.data.data.model
          this.brandoptions = res.data.data.brand
          this.ramoptions = res.data.data.ram
          this.romoptions = res.data.data.rom
          this.osoptions = res.data.data.os
          console.log(res)
        })
          .catch(function(error) {
            console.log(error)
          })
      },
      // 查看接口
      webDetail() {
        axios.post('/asset', this.detaildata, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.webGateRedactForm = res.data.data
          var statusStr = ''
          if (res.data.data.asset_status === 0) {
            statusStr = '未使用'
          } else if (res.data.data.asset_status === 1) {
            statusStr = '已使用'
          } else if (res.data.data.asset_status === 2) {
            statusStr = '其他'
          }
          this.webGateRedactForm.asset_status = statusStr
          console.log(res)
        })
          .catch((error) => {
            console.log(error)
          })
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /*****************第一层弹窗*****************/
  .testColor{
    padding: 0;
    color: #fff;
  }
  /*****************第一层弹窗*****************/
  /deep/ .box > .el-dialog{
    width: 850px;
    height: 520px;
    margin-top: 15vh !important;
    border-radius: 4px;
  }
  /*****************第一层弹窗头部*****************/
  /deep/ .box > .el-dialog > .el-dialog__header{
    width: 850px;
    height: 39px;
    line-height: 43px;
    padding: 0;
    text-indent: 20px;
    font-weight: bolder;
    border-radius: 4px;
    background-color: #e3e6ee;
  }
  /deep/ .box > .el-dialog > .el-dialog__header > .el-dialog__headerbtn{
    top: 12px;
  }
  /deep/ .box > .el-dialog > .el-dialog__header > .el-dialog__headerbtn > i{
    font-size: 18px;
    font-weight: bolder;
  }
  /*****************第一层弹窗内容*****************/
  .dialogInput{
    width: 250px;
    height: 25px;
    border: 1px solid #CCD1D7;
    border-radius: 4px;
    outline: none;
    text-indent: 15px;
  }
  input::-webkit-input-placeholder{
    color: #C0C4CC;
  }
  textarea.redactText{
    margin: 0;
    outline: none;
    width: 635px;
    height: 100px;
    border: 1px solid #ccc;
    border-radius: 4px;
    text-indent: 15px;
  }
  .longInput{
    width: 635px;
  }
  /deep/ .el-row{
    padding-bottom: 10px;
  }
  /deep/ .box > .el-dialog > .el-dialog__body{
    padding: 0 0 0 10px ;
    margin-top: 20px;
  }
  /deep/ .el-input__icon{
    line-height: 25px;
  }
  /************下拉框样式************/
  /deep/ .el-input__inner{
    height: 25px;
    width: 250px;
    outline: none;
  }
  /*****************第一层弹窗底部*****************/
  /deep/ .box > .el-dialog > .el-dialog__footer{
    border-top: 1px solid #e3e6ee;
  }
  /*****************底部按钮*****************/
  /deep/ .dialog-footer{
    padding-top: 8px;
  }
  /deep/ .dialog-footer > .el-button{
    width: 80px;
    height: 30px;
    padding: 0;
  }
</style>
